package com.wdc.service;

import com.wdc.mapper.UserMapper;
import com.wdc.pojo.User;
import org.springframework.stereotype.Service;

import java.util.List;

@Service  // 标记为 Spring 服务组件，交给容器管理
public class UserService {
    private final UserMapper userMapper;

    // 构造方法注入 Mapper
    public UserService(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    // 新增用户
    public int addUser(User user) {
        return userMapper.insertUser(user);
    }

    // 删除用户
    public int removeUser(Integer id) {
        return userMapper.deleteUserById(id);
    }

    // 修改用户
    public int editUser(User user) {
        return userMapper.updateUser(user);
    }

    // 根据 ID 查询用户
    public User getUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    // 查询所有用户
    public List<User> listAllUsers() {
        return userMapper.selectAllUsers();
    }
}